package admin

import (
	"fmt"
	"gitee.com/yangguoliang001/go-gin-vue3/QO"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/response"
	"gitee.com/yangguoliang001/go-gin-vue3/util/code"
	"github.com/gin-gonic/gin"
)

// Login 管理员登录
// @Summary 管理员登录
// @Description 管理员登录
// @Tags API.admin
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param username formData string true "用户名"
// @Param password formData string true "MD5后的密码"
// @Success 200 {object} response.TResponse{data=vo.LoginVO}
// @Failure 400 {object} response.TResponse{data=interface{}}
// @Router /api/login [post]
func (ac *adminController) Login(c *gin.Context) {
	var loginReq QO.LoginReqQO
	if err := c.ShouldBind(&loginReq); err != nil {
		response.Fail(c, code.ParamBindError, code.Text(code.ParamBindError), gin.H{"realErr": err})
		return
	}
	// token
	res, err := ac.adminService.Login(c, loginReq)
	//ac.logger()
	fmt.Println("************", res, res.MenuData)
	if err == nil {
		response.Success(c, "登录成功", gin.H{
			"token":          res.Token,
			"username":       loginReq.Username,
			"menuData":       res.MenuData,
			"actionListJson": res.ActionJsonInfo,
		})
	}
}
